package com.ylxin.servlet;

import cn.dsna.util.images.ValidateCode;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Hou
 * @version V1.0
 * @Project day42
 * @Package ${PACKAGE_NAME}
 * @Description: ${TODO}
 * @Date 2022/5/12 10:07
 */
@WebServlet(name = "ValidateCodeServlet",urlPatterns = "/validateCode")
public class ValidateCodeServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ValidateCode validateCode = new ValidateCode(150, 40, 4, 10);
        String code = validateCode.getCode();
        request.getSession().setAttribute("validateCode",code);
        validateCode.write(response.getOutputStream());
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
